#!/bin/bash

# postinst script for driver-network-ral
#
# see: dh_installdeb(1)

#set -e

# summary of how this script can be called:
#        * <postinst> \`configure' <most-recently-configured-version>
#        * <old-postinst> \`abort-upgrade' <new version>
#        * <conflictor's-postinst> \`abort-remove' \`in-favour' <package>
#          <new-version>
#        * <postinst> \`abort-remove'
#        * <deconfigured's-postinst> \`abort-deconfigure' \`in-favour'
#          <failed-install-package> <version> \`removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

PATH=/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

if [ "${BASEDIR:=/}" = "/" ]; then
    BASEDIR=""
else
    BASEDIR_OPT="-b $BASEDIR"
fi

case "$1" in
    configure)
        chown root:bin $BASEDIR/usr/share/man/man4d
	chown root:bin $BASEDIR/usr/share/man
	chown root:sys $BASEDIR/kernel
	chown root:sys $BASEDIR/kernel/drv
	chown root:sys $BASEDIR/kernel/drv/amd64
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/amd64/ral ] && rm -f $BASEDIR/kernel/drv/amd64/ral
	else
	    chmod 0755 "$BASEDIR/kernel/drv/amd64/ral"
	    chown root:sys "$BASEDIR/kernel/drv/amd64/ral"
	fi
	[ "$ZONEINST" = "1" ] || (grep -c "^ral " $BASEDIR/etc/name_to_major >/dev/null || ( add_drv -n  $BASEDIR_OPT  -i '"pci1814,201"' -m '* 0666 root sys' ral ) )
	[ "$ZONEINST" = "1" ] || (grep -c "'ral 0666 root sys'" $BASEDIR/etc/minor_perm >/dev/null || update_drv -n  -a $BASEDIR_OPT  -m 'ral 0666 root sys' clone)
	
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument '$1'" >&2
        exit 1
    ;;
esac



# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

